package com.sunma.assetsin.controller;

import com.sunma.assetsin.domain.AssetsIn;
import com.sunma.assetsin.service.IAssetsInService;
import com.sunma.common.annotation.Log;
import com.sunma.common.core.controller.BaseController;
import com.sunma.common.core.domain.AjaxResult;
import com.sunma.common.core.page.TableDataInfo;
import com.sunma.common.enums.BusinessType;
import com.sunma.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产入库Controller
 * 
 * @author sunma
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/assetsin/assetsin")
public class AssetsInController extends BaseController
{
    @Autowired
    private IAssetsInService assetsInService;

    /**
     * 查询资产入库列表
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetsIn assetsIn)
    {
        startPage();
        List<AssetsIn> list = assetsInService.selectAssetsInList(assetsIn);
        return getDataTable(list);
    }

    /**
     * 导出资产入库列表
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:export')")
    @Log(title = "资产入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetsIn assetsIn)
    {
        List<AssetsIn> list = assetsInService.selectAssetsInList(assetsIn);
        ExcelUtil<AssetsIn> util = new ExcelUtil<AssetsIn>(AssetsIn.class);
        util.exportExcel(response, list, "资产入库数据");
    }

    /**
     * 获取资产入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetsInService.selectAssetsInById(id));
    }

    /**
     * 新增资产入库
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:add')")
    @Log(title = "资产入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetsIn assetsIn)
    {
        return toAjax(assetsInService.insertAssetsIn(assetsIn));
    }

    /**
     * 修改资产入库
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:edit')")
    @Log(title = "资产入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetsIn assetsIn)
    {
        return toAjax(assetsInService.updateAssetsIn(assetsIn));
    }

    /**
     * 删除资产入库
     */
    @PreAuthorize("@ss.hasPermi('assetsin:assetsin:remove')")
    @Log(title = "资产入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetsInService.deleteAssetsInByIds(ids));
    }
}
